var ctx=window.daijia.ctx;

$(document).ready(function(){
	$("#startTime").datetimepicker({ format: 'yyyy-mm-dd', language: 'zh-CN', minView: 'month', pickDate: true, pickTime: false, inputMask: false, autoclose: true, startDate: new Date()});
	$("#endTime").datetimepicker({ format: 'yyyy-mm-dd', language: 'zh-CN', minView: 'month', pickDate: true, pickTime: false, inputMask: false, autoclose: true, startDate: new Date()});
	
	$("#submit_button").click(function(){
		

		

		
		if(""==$("#title").val()){
			$.scojs_message("请填写标题", $.scojs_message.TYPE_ERROR);
			return false;
		}
		
		if($("#code").val()==""){
			$.scojs_message("请填写编码", $.scojs_message.TYPE_ERROR);
			return false;
		}
		
		
		if(!$("input[name=type]:checked").val()==1){
			if($("#money").val()==""){
				 $.scojs_message("请输入抵扣金额", $.scojs_message.TYPE_ERROR);
	 			return false;
			}
			
			
		}
		else if(!$("input[name=type]:checked").val()==0){
			if($("#discount").val()==""){
				 $.scojs_message("请输入打折数", $.scojs_message.TYPE_ERROR);
	 			return false;
			}
			
		} 
		
		
		if(""==$("#number").val()){
			$.scojs_message("请填写最大发放数量", $.scojs_message.TYPE_ERROR);
			return false;
		}
		
		
		if($("#eachLimit").val()==""){
		   $.scojs_message("请填写每人最多领取次数", $.scojs_message.TYPE_ERROR);
		   return false;
		}
		
		
		if($("#end").val()!=""){
			if($("#start").val()>$("#end").val()){
				 $.scojs_message("展示起始日期不能大于结束日期", $.scojs_message.TYPE_ERROR);
				 return false;
			}
		}
		
		
		
		
		
		
		
		$.post(ctx+'/couponrule/createCouponRule',$("#submit_form").serialize(),function(data){
			if(data.success){
				$.scojs_message("创建成功", $.scojs_message.TYPE_OK);
				window.location=ctx+"/activitymanage/activitymanage";
			}
			else{
				$.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
				$("#submit_button").attr("disabled",false);
			}
		});
		
	});
	
	

});